﻿using Cxuu.Models;
using Cxuu.Service;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Cxuu.Web.Home
{
    [Area("Home")]
    public class InfoController : Base
    {
        private readonly ArticleService _articleService;
        private readonly ArticleCateService _articleCateService;

        public InfoController(ArticleService articleService, ArticleCateService articleCateService)
        {
            _articleService = articleService;
            _articleCateService = articleCateService;
        }

        /// <summary>
        /// 根据ID查询详细内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> IndexAsync(int? id)
        {
            if (id == null)
            {
                return Ok("请勿非法输入！");
            }
            ViewArticleAndContent article = await _articleService.GetAsync(id);
            if (article == null)
            {
                return NotFound();
            }
            ArticleCate cateInfo = await _articleCateService.GetOneAsync(article.Cid);
            ViewBag.info = article;
            ViewBag.cateInfo = cateInfo;
            return View();
        }

    }
}
